cmake_minimum_required(VERSION 3.12)

# 项目设置
set_property(GLOBAL PROPERTY USE_FOLDERS ON) # 打开允许创建文件夹的开关

set(CMAKE_CXX_STANDARD 11) # 设置C++ 标准版本
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 检测系统并设置相关选项
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
    add_compile_options("/utf-8")
    set(VCPKG_TARGET_TRIPLET "x64-windows" CACHE STRING "Vcpkg target triplet")
else()
    set(VCPKG_TARGET_TRIPLET "x64-linux-dynamic" CACHE STRING "Vcpkg target triplet")
endif()

# 设置工具链文件路径
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
    if(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
        set(CMAKE_TOOLCHAIN_FILE xxx/vcpkg/scripts/buildsystems/vcpkg.cmake)
    else()
        set(CMAKE_TOOLCHAIN_FILE xxx/vcpkg/scripts/buildsystems/vcpkg.cmake)
    endif()
endif()
include(${CMAKE_TOOLCHAIN_FILE}) # 包含外部工具链文件

# 项目目录设置
set(PROJECT_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
include_directories(${PROJECT_ROOT_DIR}/include) # 设置全局包含路径
# 输出目录设置
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_ROOT_DIR}/Debug)
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${PROJECT_ROOT_DIR}/Debug)
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${PROJECT_ROOT_DIR}/Debug)

    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_ROOT_DIR}/Release)
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${PROJECT_ROOT_DIR}/Release)
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${PROJECT_ROOT_DIR}/Release)

    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${PROJECT_ROOT_DIR}/RelWithDebInfo)
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${PROJECT_ROOT_DIR}/RelWithDebInfo)
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO ${PROJECT_ROOT_DIR}/RelWithDebInfo)

    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${PROJECT_ROOT_DIR}/MinSizeRel)
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_MINSIZEREL ${PROJECT_ROOT_DIR}/MinSizeRel)
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_MINSIZEREL ${PROJECT_ROOT_DIR}/MinSizeRel)

# 后缀设置
set(CMAKE_DEBUG_POSTFIX "d")
set(CMAKE_RELEASE_POSTFIX "")
set(CMAKE_RELWITHDEBINFO_POSTFIX "_rel")
set(CMAKE_MINSIZEREL_POSTFIX "_min")

set(BUILD_SHARED_LIBS ON)

project(osg-template)
add_subdirectory(src)
# 复制第三方库文件
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
    if(CMAKE_BUILD_TYPE STREQUAL "Debug")
        file(GLOB THIRD_PARTY_LIBS_DIR "${PROJECT_ROOT_DIR}/build/vcpkg_installed/x64-windows/debug/plugins/osgPlugins-3.6.5/*")
        file(COPY ${THIRD_PARTY_LIBS_DIR} DESTINATION ${PROJECT_ROOT_DIR}/Debug/osgPlugins-3.6.5)
        file(COPY ${PROJECT_ROOT_DIR}/build/vcpkg_installed/x64-windows/bin/jpeg62.dll DESTINATION ${PROJECT_ROOT_DIR}/Debug)
    else()
        file(GLOB THIRD_PARTY_LIBS_DIR "${PROJECT_ROOT_DIR}/build/vcpkg_installed/x64-windows/plugins/osgPlugins-3.6.5/*")
        file(COPY ${THIRD_PARTY_LIBS_DIR} DESTINATION ${PROJECT_ROOT_DIR}/Release/osgPlugins-3.6.5)
        file(COPY ${PROJECT_ROOT_DIR}/build/vcpkg_installed/x64-windows/bin/jpeg62.dll DESTINATION ${PROJECT_ROOT_DIR}/Release)
    endif()
endif()

# 输出信息
message("CMAKE_HOST_SYSTEM_NAME: ${CMAKE_HOST_SYSTEM_NAME}")
message("CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
message("CMAKE_MODULE_PATH: ${CMAKE_MODULE_PATH}")
message("CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
